﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Threading.Tasks;
using RestServices.Response.SkyDrive;

namespace RestServices
{
    public class LiveLoginService
    {
        public string RequestUser(string token)
        {
            //http://apis.live.net/v5.0/USER_ID?access_token=ACCESS_TOKEN
            string UrlRequest = "https://apis.live.net/v5.0/me?access_token=" + token;
            return (UrlRequest);
        }

        public string RequestRefresh(string clientID, string ClientSecret, string RefreshToken)
        {
            //https://login.live.com/oauth20_authorize.srf?client_id=CLIENT_ID&scope=wl.signin%20wl.skydrive_update&response_type=RESPONSE_TYPE&redirect_uri=REDIRECT_URL
            string UrlRequest = "https://login.live.com/oauth20_token.srf?" +
                                 "client_id=" + clientID +
                                 "&redirect_uri=https://oauth.live.com/desktop" +
                                 "&client_secret=" + ClientSecret +
                //"&scope=wl.signin%20wl.skydrive_update%20wl.offline_access&response_type=code&redirect_uri=https://login.live.com/oauth20_desktop.srf";
                                 "&refresh_token=" + RefreshToken +
                                 "&grant_type=refresh_token" +
                //"&scope=wl.signin%20wl.skydrive_update%20wl.offline_access&response_type=token&redirect_uri=https://oauth.live.com/desktop";
                //"&scope=wl.signin%20wl.skydrive_update%20wl.offline_access&redirect_uri=https://oauth.live.com/desktop";
                                 "";

            return (UrlRequest);
        }

        public string RequestSignOut(string clientID)
        {
            //https://login.live.com/oauth20_logout.srf?client_id=CLIENT_ID&redirect_uri=REDIRECT_URL
            string UrlRequest = "https://login.live.com/oauth20_logout.srf?client_id=" + clientID + "&redirect_uri=https://oauth.live.com/desktop";
            return (UrlRequest);
        }

        public string RequestSignIn(string clientID, string scope)
        {
            //https://login.live.com/oauth20_authorize.srf?client_id=CLIENT_ID&scope=wl.signin%20wl.skydrive_update&response_type=RESPONSE_TYPE&redirect_uri=REDIRECT_URL
            string UrlRequest = "https://login.live.com/oauth20_authorize.srf?client_id=" +
                                 clientID +
                //"&client_secret=" + ClientSecret + 
                //"&scope=wl.signin%20wl.skydrive_update%20wl.offline_access&response_type=code&redirect_uri=https://login.live.com/oauth20_desktop.srf";
                                 "&scope="+scope+"&response_type=code&redirect_uri=https://oauth.live.com/desktop";

            return (UrlRequest);
        }

        public string RequestToken(string clientID, string ClientSecret, string Code)
        {
            //https://login.live.com/oauth20_authorize.srf?client_id=CLIENT_ID&scope=wl.signin%20wl.skydrive_update&response_type=RESPONSE_TYPE&redirect_uri=REDIRECT_URL
            string UrlRequest = "https://login.live.com/oauth20_token.srf?" +
                                 "client_id=" + clientID +
                                 "&redirect_uri=https://oauth.live.com/desktop" +
                                 "&client_secret=" + ClientSecret +
                //"&scope=wl.signin%20wl.skydrive_update%20wl.offline_access&response_type=code&redirect_uri=https://login.live.com/oauth20_desktop.srf";
                                 "&code=" + Code +
                                 "&grant_type=authorization_code" +
                //"&scope=wl.signin%20wl.skydrive_update%20wl.offline_access&response_type=token&redirect_uri=https://oauth.live.com/desktop";
                //"&scope=wl.signin%20wl.skydrive_update%20wl.offline_access&redirect_uri=https://oauth.live.com/desktop";
                                 "";

            return (UrlRequest);
        }


    }
}
